package library.Configuration;

import java.net.URL;

import org.apache.log4j.*;

/**
 * This class contains only static methods, that can be called at any time
 * in any methods
 * 
 * This must be the entry point to read any value of the configuration file
 * 
 * @author JNC
 */
public class Configuration {
    
    /**
     * The configuration file can be accessed via an URL (applet mode) or via a
     * file (application mode)
     */
    private static Config _config;
    /**
     * The log4j log
     */
    @SuppressWarnings("unused")
	private static final Logger _logger = Logger.getLogger(ConfigFromURL.class);    
    
    /**
     * Sets the config filename when the filename is an URL
     * @param myURL
     * The URL that represents the config filename
     */
    public static void setConfigFilename(URL myURL) {
        _config = new ConfigFromURL();
        ((ConfigFromURL)_config).setConfigFilename(myURL);
    }
    
    /**
     * Sets the config filenqme when the filenqme is a file reference
     * @param myFilename
     * The file reference that the represents the flename
     */
    public static void setConfigFilename(String myFilename) {
        _config = new ConfigFromFile();
        ((ConfigFromFile)_config).setConfigFilename(myFilename);
    }
    
    /**
     * Gets a boolean property
     * @param myKey
     * The keyword of the requested property
     * @return
     * The boolean value associated to the keyword
     */
    public static boolean getBooleanProperty(String myKey) {
        return _config.getBooleanProperty(myKey);
    }
    
    /**
     * Gets an int property
     * @param myKey
     * The keyword of the requested property
     * @return
     * The int value associated to the keyword
     */
    public static int getIntProperty(String myKey) {
        return _config.getIntProperty(myKey);
    }
    
    /**
     * Gets a path property
     * The separator between the name of the directory will be adapted to the OS
     * @param myKey
     * The keyword of the requested property
     * @return
     * The path associated to the keyword
     */
    public static String getPathProperty(String myKey) {
        return _config.getPathProperty(myKey);
    }
    
    /**
     * Gets a String property
     * @param myKey
     * The keyword of the requested property
     * @return
     * The String value associated to the keyword
     */
    public static String getStringProperty(String myKey)  {
        return _config.getStringProperty(myKey);
    }
}
